<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('发射机节目设置')"/>
</head>
<style>
	.layui-form-label {
		width: 200px !important;
		text-align: left !important;
	}

	.layui-form-item .layui-input-inline {
		width: 200px !important;
		margin-bottom: 0px !important;
	}

	.layui-form-item-te {
		margin-bottom: 0px !important;
	}
</style>
<body class="pear-container">
<div class="layui-card">
	<form class="layui-form layui-form-pane" action="" id="programform"  lay-filter="programform">
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 5%;">
			<label class="layui-form-label" style="width: 7%">台站ID</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="stationCode" name="stationCode" lay-verify="required"
						lay-filter="getTransmitter" >
				</select>
			</div>
			<label class="layui-form-label" style="width: 7%">发射机ID</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="transCode" name="transCode" lay-verify="required"  >
				</select>
			</div>
			<label class="layui-form-label" style="width: 7%">发射机通道号</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="taskId" name="taskId" lay-verify="required"  >
					<option value="0">通道0</option>
					<option value="1">通道1</option>
					<option value="2">通道2</option>
					<option value="3">通道3</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 1%;">
			<label class="layui-form-label" style="width: 7%">任务开始时间</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="sendDateTime" name="sendDateTime" autocomplete="off" placeholder="HH:mm:ss" lay-verify="required" >
			</div>
			<label class="layui-form-label" style="width: 7%">任务结束时间</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="sendDateEndTime" name="sendDateEndTime" autocomplete="off" placeholder="HH:mm:ss" lay-verify="required" >
			</div>
			<label class="layui-form-label" style="width: 7%">操作类型</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="operType" name="operType" lay-verify="required"  >
					<option value="1">新增</option>
					<option value="2">替换/修改</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 1%;">
			<label class="layui-form-label" style="width: 7%">工作频率(3200~26100HZ)</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="channelFreq" name="channelFreq" autocomplete="off"  lay-verify="required" >
			</div>
			<label class="layui-form-label" style="width: 7%">通道状态</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="channelRfChState" name="channelRfChState" lay-verify="required"  >
					<option value="0">开</option>
					<option value="1">关</option>
				</select>
			</div>
			<label class="layui-form-label" style="width: 7%">跳频时隙(0 ~ 50)</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="channelTimeSlot" name="channelTimeSlot" autocomplete="off" lay-verify="required"  >
			</div>
		</div>
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 1%;">
			<label class="layui-form-label" style="width: 7%">输出功率(0~+200)</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="channelEqualization" name="channelEqualization" autocomplete="off" lay-verify="required"  >
			</div>
			<label class="layui-form-label" style="width: 7%">调制模式</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="channelRfChMod" name="channelRfChMod" lay-verify="required"  >
					<option value="0">单音</option>
					<option value="1">AM</option>
					<option value="2">FM</option>
				</select>
			</div>
			<label class="layui-form-label" style="width: 7%">调制宽度(1000hz-4000hz)</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="channelRfChBand" name="channelRfChBand" autocomplete="off" lay-verify="required" >
			</div>
		</div>
		<div class="layui-form-item layui-form-item-te" style="padding-left: 10%;padding-top: 1%;">
			<label class="layui-form-label" style="width: 7%">音源</label>
			<div class="layui-input-inline" style="width: 12%">
				<select id="channelRfChASource" name="channelRfChASource" lay-verify="required"  >
					<option value="0">白噪声</option>
					<option value="1">1k单音</option>
					<option value="2">外部音源</option>
					<option value="3">静音</option>
					<option value="4">文件白噪声</option>
					<option value="5">文件打击乐</option>
					<option value="6">播放URL音频</option>
				</select>
			</div>
			<label class="layui-form-label" style="width: 7%">音源地址</label>
			<div class="layui-input-inline" style="width: 12%">
				<input type="text" class="layui-input" id="channelRfChAUrl" name="channelRfChAUrl" autocomplete="off" lay-verify="required" >
			</div>
			<label class="layui-form-label" style="width: 7%">循环周期</label>
			<div class="layui-input-inline"  style="width: 20%">
				<select id="period" name="programPeriod" lay-verify="required"  xm-select="select5" xm-select-skin="default">
					<option value="1">星期一</option>
					<option value="2">星期二</option>
					<option value="3">星期三</option>
					<option value="4">星期四</option>
					<option value="5">星期五</option>
					<option value="6">星期六</option>
					<option value="7">星期天</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block" style="text-align: center; margin-right:10%;padding-top: 5%;">
				<button class="layui-btn" th:type="button" lay-filter="set" lay-submit>
					添加
				</button>
				<button class="layui-btn" th:type="button" lay-filter="closeProgram" onclick="closeProgram()">
					关闭
				</button>
			</div>
		</div>
	</form>
</div>
</body>
<th:block th:include="include :: footer"/>
<script>
	layui.use(['table', 'form', 'popup', 'jquery', 'laydate','element', 'util','layer','select'], function () {
		let form = layui.form;
		let popup = layui.popup;
		let laydate = layui.laydate;
		let MODULE_PATH = "/system/program/";

		laydate.render({
			elem: '#sendDateTime',
			type: 'time',
			format: 'HH:mm:ss',
			theme: 'grid'
		});
		laydate.render({
			elem: '#sendDateEndTime',
			type: 'time',
			format: 'HH:mm:ss',
			theme: 'grid'
		});
		form.on('select(getTransmitter)', function (data) {
			getTransmitter(data.value);
		});

		//监听提交
		form.on('submit(set)', function(){
			programSet();
			return false;
		});
		function getRecentDay(hour){
			const today = new Date();
			const targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * hour;
			today.setTime(targetday_milliseconds);
			const tYear = today.getFullYear();
			let tMonth = today.getMonth();
			let tDate = today.getDate();
			let tHour = today.getHours();
			let tM = today.getMinutes();
			let ts = today.getSeconds();
			tMonth = doHandleMonth(tMonth + 1);
			tDate = doHandleMonth(tDate);
			return tYear+"-"+tMonth+"-"+tDate + " "+tHour+":" + tM + ":" +ts;
		}
		function doHandleMonth(month){
			let m = month;
			if(month.toString().length === 1){
				m = "0" + month;
			}
			return m;
		}
		/**
		 * 终端系统信息设置模板(后续去除系统信息无需设置)
		 */
		window.programSet = function () {
			var d = {};
			var t = $('#programform').serializeArray();
			$.each(t, function() {
				d[this.name] = this.value;
			});
			var programPeriod="";
			for (let i = 0; i < d["programPeriod"].split(",").length; i++) {
				if(i==0){
					programPeriod = d["programPeriod"].split(",")[i];
				}else{
					programPeriod = programPeriod + "," + d["programPeriod"].split(",")[i];
				}
			}
			d["programPeriod"] = programPeriod;
			$.ajax({
				url: MODULE_PATH + 'addProgram',
				type: 'POST',
				contentType: 'application/json;charset=UTF-8',
				data: JSON.stringify(d),
				success: function (data) {
					if (data.code === 200) {
						popup.success(data.msg);
						window.parent.location.reload();
						varindex = parent.layer.getFrameIndex(window.name);
						parent.layer.close(index);
					} else {
						popup.failure(data.msg);
					}
				},
				error: function () {
					popup.failure("添加发射机节目接口访问失败!")
				}
			});
		}
		window.closeProgram = function () {
			window.parent.location.reload();
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		}
		$.ajax({
			url:  '/system/transmitter/getStations',
			type: 'get',
			contentType: 'application/json;charset=UTF-8',
			success: function (data) {
				$("#stationCode").empty();
				if (data.code == 0) {
					$.each(data.data, function (index, item) {
						$("#stationCode").append(new Option( item.title, item.id));// 下拉菜单里添加元素
					});
					layui.form.render("select");
					if(data.data.length>0){
						getTransmitter(data.data[0].id);
					}
				} else {
					popup.failure(data.msg);
				}
			},
			error: function () {
				popup.failure("获取台站接口访问失败!")
			}
		});
		function getTransmitter(stationCode){
			$.ajax({
				url:  "/system/transmitter/getTransmitter?stationCode=" + stationCode,
				type: 'get',
				contentType: 'application/json;charset=UTF-8',
				success: function (data) {
					$("#transCode").empty();
					if (data.code == 200) {
						$.each(data.data, function (index, item) {
							$("#transCode").append(new Option( item.transName, item.id));// 下拉菜单里添加元素
						});
						layui.form.render("select");
					} else {
						popup.failure(data.msg);
					}
				},
				error: function () {
					popup.failure("获取发射机接口访问失败!")
				}
			});
		}
	})
</script>
</html>